home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / 2020HalfGateway / 2020HalfGateway.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  13.5 KB  |  392 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        2020HalfGateway.h
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __2020HALFGATEWAY__
  15. #define __2020HALFGATEWAY__
  16.  
  17. #ifndef __2020LETTER__
  18. #include "2020Letter.h"
  19. #endif
  20.  
  21. #ifndef __2020HALFGATEWAYMISC__
  22. #include "2020HalfGatewayMisc.h"
  23. #endif
  24.  
  25. #ifndef __AOCEHGWYTYPES__
  26. #include "AOCEHalfGatewayTypes.h"
  27. #endif
  28.  
  29. #ifndef __COREGATEWAYTYPES__
  30. #include "CoreGatewayTypes.h"
  31. #endif
  32.  
  33. #ifndef __EVENTCOUNTDOWN__
  34. #include "EventCountdown.h"
  35. #endif
  36.  
  37. #ifndef __HALFGATEWAY__
  38. #include "HalfGateway.h"
  39. #endif
  40.  
  41. #ifndef __RAMTUPLEDATABASE__
  42. #include "RamTupleDatabase.h"
  43. #endif
  44.  
  45. #ifndef __OCEOBJECTS__
  46. #include "OCEObjects.h"
  47. #endif
  48.  
  49. #ifndef __THREADCLASSES__
  50. #include "ThreadClasses.h"
  51. #endif
  52.  
  53. /***********************************|****************************************/
  54.  
  55. class TVirtualMacFile;
  56. class TVirtualFolder;
  57.  
  58. /***********************************|****************************************/
  59.  
  60. class TRLIList;
  61.  
  62. /***********************************|****************************************/
  63.  
  64. class T2020HalfGateway : public THalfGateway
  65. {
  66. public:
  67.  
  68.     T2020HalfGateway();
  69.     virtual ~T2020HalfGateway ();
  70.  
  71. public:
  72. //
  73. //    HALF-GATEWAY SETUP METHODS
  74. //
  75.     virtual Boolean Setup (TMailGateway& gateway, short vRefNum, long dirID, const char* gatewayName);
  76.  
  77. //
  78. //    HALF-GATEWAY RECOVERY METHODS
  79. //
  80.     virtual Boolean BeginRecoveryPhase(void);
  81.     virtual Boolean IsRecoveryDone(void);
  82.     virtual Boolean FinishRecoveryPhase(void);
  83.  
  84.     virtual Boolean ResendLetter (TLetter* letter);
  85.     virtual Boolean RereceiveLetter (TLetter* letter);
  86.  
  87. //
  88. //    HALF-GATEWAY OPERATION METHODS
  89. //
  90.     virtual Boolean Run (void);
  91.     virtual Boolean    SendLetter(TLetter *letter);
  92.     virtual Boolean    ReceiveLetter(TLetter* letter);
  93.  
  94.     virtual Boolean    PrepareToShutDown(long inHowManySeconds);
  95.     virtual Boolean    IsHalfGatewayShuttingDown(void);
  96.     virtual Boolean    IsHalfGatewayReadyToShutDown(void);
  97.     virtual Boolean    CancelHalfGatewayShutdown (void);
  98.     virtual Boolean    ShutDown(void);
  99.     virtual Boolean    GetStatusStr ( Str255& statusStr ) const;
  100.     
  101.     virtual Boolean GetStatusItem(const ATupleKey& key, ADataItem& buffer);
  102.     virtual Boolean SetStatusItem(const ATupleKey& key, const ADataItem& buffer);
  103.     
  104.     virtual Boolean HandleMonitoringEvent ( const ADataItem& event );
  105.     
  106. //
  107. //    2020 HALF-GATEWAY SPECIFIC METHODS
  108. //    ==================================
  109. //
  110.  
  111.                 //    Create all of the 'normal' execution threads for this half gateway.
  112. protected:        void                        CreateThreads ( void );
  113.  
  114.     //    This method becomes the '2Scn' thread.  It periodically checks if there is a letter
  115.     //    available from 2020 which our gateway needs to process.  If there is, it creates a
  116.     //    T2020Letter object for the letter, and then sends this letter to the mail gateway.
  117. public:
  118.     void Scan2020ForOutgoingLetters(void);
  119.  
  120.     //    This method becomes the '2Put' thread.  It periodically checks if there are any items
  121.     //    in the fReceivedLetters list.  If there are items in there, it calls the
  122.     //    DoReceiveALetter() method with each item.
  123.     void PutReceivedLettersInto2020(void);
  124.  
  125.     //    This method becomes the '2Sen' thread.  It periodically checks the list fLettersFromOCEToBeSent,
  126.     //    and does a SendLetter for each one.
  127.     void SendOCELettersToMailGateway(void);
  128.  
  129.     //    This method becomes the '2Rec' thread.  It periodically checks the list fReportsFromOCEToBeProcessed,
  130.     //    and does a HandleRecipientReport() for each one.
  131.     void ProcessLetterRecipientReports(void);
  132.  
  133.     //    This method becomes the '2Per' thread.  It handles periodic tasks.
  134. protected:    void PeriodicTasks();
  135.             friend void T2020DoPeriodicTasksWrapper(unsigned long g, unsigned long h);
  136.     
  137.  
  138.             //    This method updates the fAvailableDirectories field.  This list contains the
  139.             //    names, discriminators, and flags for all of the available 2020 directories.
  140. public:        void UpdateDatabaseOfAvailable2020Directories();
  141.  
  142.             virtual Boolean                        UpdateExtendedDirectoriesList ( );        
  143.             virtual TForeignDNode*                 GetExtendedDirectoryForeignDNode ( OSType directoryType ) const;
  144.             
  145.             //    This method handles the recipient reports which we get from 2020.
  146.             Boolean HandleRecipientReport (T2020Letter* report);
  147.         
  148.         
  149.             //    This method puts a report for the given letter into OCE.  It return true if
  150.             //    there were no problems, false otherwise.
  151. public:        Boolean CreateRecipientReportForLetter(T2020Letter* letter);
  152.         
  153.             //
  154.             //    These methods support path names to be converted to dNodeNumbers, and vice versa.
  155.             //
  156. public:        Boolean FindDNodeForPathName(const TPathName& pathName, const TDirectory& directory, DNodeNum& dNodeNumber);
  157. public:        Boolean FindPathNameForDNode(const DNodeNum& dNodeNumber, const TDirectory& directory, TPathName& pathName);
  158.  
  159.             //    Get the AOCE directory system that we're attached to.
  160. public:        virtual const TDirectory &            GetAOCEDirectory () const;
  161.  
  162.             /***********************************|****************************************/
  163.             //    
  164.             //    Finding ADAS addresses
  165.             //
  166. public:        unsigned long FindADASAddresses (const TRString& recordName, const TRString& recordType, const DNodeNum clusterToSearch, TRecordID& resultAddress, unsigned long maxToFind = 10);
  167.             unsigned long FindADASAddresses (const TRString& recordName, const TRString& recordType, const TRLI& clusterToSearch, TRecordID& resultAddress, unsigned long maxToFind = 10);
  168.             unsigned long FindADASAddresses (const TRString& recordName, const TRString& recordType, TRecordID& resultAddress, unsigned long maxToFind = 10);
  169.             unsigned long FindADASAddresses (const TCreationID& cid, const DNodeNum dNode, TRecordID& result);
  170.             unsigned long FindADASAddresses (const TCreationID& cid, const DNodeNum dNode, const TDirectory& directory, TRecordID& result);
  171.             
  172.             
  173. protected:    TRLIList* GetChildClusters ();
  174.             TRLIList* GetChildClusters (const TRLI& parentCluster);
  175.  
  176.  
  177.  
  178.             /***********************************|****************************************/
  179.             //
  180.             //    Finding, examing, and creating ADAS Records
  181.             //
  182. public:        Boolean                                GetADASAttributeValue ( const TRecordID& whichRecord,
  183.                                                                         const TRString& attributeType,
  184.                                                                         void * dataPtr, unsigned long dataSize );
  185.             Boolean                                GetADASAttributeValue ( const TRecordID& whichRecord,
  186.                                                                         const TRString& attributeType,
  187.                                                                         ADataItem& value );
  188.  
  189. protected:
  190.             virtual void                        ResetStatistics ( );
  191.             virtual void                        SetStatusStr ( Str255 statusStr );
  192.     
  193. //
  194. //    RECOVERY PHASE METHODS
  195. //    ======================
  196. //
  197.     //    This method becomes the '2rsc' thread, which is only used during the recovery phase.
  198.     //    It scans OCE and re-sends any letter which is not 'done', in order to insure that
  199.     //    mail is not lost if the gateway crashes or is shut down.
  200.     protected:
  201.     void ResendLettersAtStartup();
  202.     friend void DoResendLettersAtStartupWrapper(unsigned long g, unsigned long h);
  203.  
  204. //
  205. //    High-Level Events:  The 'main event' loop must call these if a high-level event
  206. //    with type kMailAppleMailCreator type occurs.
  207.     public:
  208.     Boolean                            HandleAppleMailHighLevelEvent ( const EventRecord& event );
  209.     
  210.     protected:    //    These get called by HandleAppleMailHighLevelEvent
  211.     OSErr                            AppleEventMsgPendingEvent ( void );
  212.     OSErr                            AppleEventAdminEvent ( void );
  213.  
  214.  
  215. protected:
  216. /***********************************|****************************************/
  217.     OSErr                             CreateAOCEForwarderRecord ( );
  218.     void                             SetupServerIdentity ( );
  219.     void                             SetupServerQueueID ( );
  220.     Boolean                            SetupMailRoutingInformation ( );
  221.  
  222. public:
  223.     AuthIdentity                    GetForwarderIdentity () const;
  224.     long                            GetServerQueueID () const;
  225.     
  226.     AddrBlock                        GetAOCEServerHint ( ) const;
  227.  
  228.     typedef OSErr DirToolboxCallFunc ( DirParamBlock* pb );
  229.     OSErr                             AOCEMakeDirToolboxCallWithRetry ( DirToolboxCallFunc dirToolboxCall, DirParamBlock* pb );
  230.  
  231.     typedef OSErr AuthToolboxCallFunc ( AuthParamBlock* pb );
  232.     OSErr                             AOCEMakeAuthToolboxCallWithRetry ( AuthToolboxCallFunc authToolboxCall, AuthParamBlock* pb );
  233.     
  234. //    These all are called as part of the process of putting a letter into 2020
  235. protected:
  236.     void ReceiveALetter (TLetter *letter);
  237.  
  238.             MailMsgRef         CreateAOCELetter () const;
  239.             void            PutBLJLetterIDIntoLetter ( const MailMsgRef letterRef, short attrID, const BLJLetterID& id) const;
  240.             void            SubmitAOCELetter ( MailMsgRef& letterRef ) const;
  241.             void            AbortAOCELetter ( MailMsgRef& letterRef ) const;
  242.             
  243.     void PutAttributeIntoLetter (long letterRef, short attrID, void *data, short dataSize) const;
  244.  
  245.     Boolean PutRecipientIntoLetter (long letterRef, short attrID, const OCERecipient& oceRecipient, Boolean responsible);
  246.     Boolean PutRecipientIntoLetter (long letterRef, short attrID, const TRecordID& recordID, Boolean responsible);
  247.     Boolean PutRecipientIntoLetter (long letterRef, short attrID, TRecipient* recipient, Boolean responsible);
  248.  
  249.      Boolean PutStandardRecipientIntoLetter (long letterRef, short attrID, TRecipient* recipient, Boolean responsible );
  250.     Boolean PutExternalRecipientIntoLetter (long letterRef, short attrID, TRecipient* recipient, Boolean responsible );
  251.     
  252.     void PutIndicationsIntoLetter(long letterRef, TLetter* receivedLetter);
  253.     void PutContentIntoLetter (long letterRef, TLetter *receivedLetter);
  254.     void PutBlockIntoLetter(long letterRef, void* blockData, unsigned long blockSize);
  255.     void PutPictureIntoLetter (long letterRef, TLetter* receivedLetter);
  256.     void PutEnclosuresFolderIntoLetter (long letterRef, TVirtualFolder *enclosuresFolder);
  257.     void PutVirtualMacFileIntoEnclosures (long letterRef, long dirID, TVirtualMacFile* macFile);
  258.     void PutVFolderIntoLetterEnclosures (long letterRef, long parentDirID, TVirtualFolder* folder, long& nextDirID);
  259.  
  260. #if debug
  261. public:
  262. #else
  263. protected:
  264. #endif
  265.     short                            fWorkingVRefNum;        //    the vRefNum and dirID of the 'BovineWorking'
  266.     long                            fWorkingDirID;            //    folder we should store all of our info into.
  267.     
  268.     Boolean                            fShuttingDown;            // this is set to true when the gateway is trying
  269.     
  270.     TDirectory                        fAOCEDirectoryWeServe;
  271.     
  272.     OSType                            fOurGatewayMailExtensionType;
  273.     TRLI                            fOurGatewayMailRLI;
  274.     TDirectory                        fOurGatewayMailDirectory;
  275.  
  276.     TRecordID                        fOurForwarderRecord;
  277.     
  278.     AuthIdentity                    fForwarderIdentity;        // this is the 'validated' identity for this server
  279.     long                            fServerQueueID;
  280.     long                            fEnumerateStartSeqNum;    // this is the 'next' letter sequence number, which we use
  281.  
  282.     Boolean                            fInRecoveryPhase;
  283.     TThread*                        fRecoveryPhaseScanThread;
  284.     TThread*                        fRunThreadH;
  285.     TThread*                        fScan2020ThreadH;
  286.     TThread*                        fPutLettersInto2020ThreadH;
  287.     TThread*                        fSendLettersFromOCEToMailGatewayThreadH;
  288.     TThread*                        fProcessLetterRecipientReportsThreadH;
  289.     TThread*                        fPeriodicTasksThread;
  290.     
  291.     //    This tuple database contains all of the directories, their discriminators, et al.,
  292.     //    which are connected to this 2020 system.
  293.     TRamTupleDatabase                fAvailable2020Directories;
  294.  
  295.     unsigned long                    fNextTimeToUpdateListOfKnownExtendedDirectories;
  296.     TSortedForeignDNodeList            fKnownExtendedDirectories;
  297.  
  298.     TEventCountdown                    fLettersWaitingForRecipientReportsCountdownTimer;
  299.     
  300.     AddrBlock                        fAOCEServerHint;
  301.     
  302.     TLetterQueue                    fReceivedLetters;
  303.     T2020LetterQueue                fLettersFromOCEToBeSent;
  304.     T2020LetterQueue                fReportsFromOCEToBeProcessed;
  305.     TSharedLetterList                fLettersWaitingForRecipientReports;
  306.     
  307.     
  308.     //
  309.     //    STATUS ITEMS
  310.     //    ============
  311.     //
  312.     Boolean                            fDoNotSendLetters;
  313.     Boolean                            fDoNotReceiveLetters;
  314.     
  315.     unsigned long                    fLettersSentToAOCE;
  316.     unsigned long                    fLettersReceivedFromAOCE;
  317.     unsigned long                    fTotalKOfContentSentToAOCE;
  318.     unsigned long                    fTotalKOfEnclosuresSentToAOCE;
  319.     
  320.     long                            fAOCEToolboxVersion;
  321.     long                            fAOCEMailServerVersion;
  322.     
  323.     TRString                        fOurGatewayDescription;
  324.     
  325.     Str255                            fStatusStr;
  326. };
  327.  
  328. //    This struct is used to store information about a letter when
  329. //    we put the letter into OCE.  Later, all letter reports for this
  330. //    letter will include this struct in the letter report; and our
  331. //    halfgateway thes uses this info to find the original letter in
  332. //    the fLettersWaitingForRecipientReports list.
  333.  
  334. typedef struct MyGWYIBlockRecord {
  335.     unsigned long    version;
  336.     BLJLetterID        letterID;
  337. } MyGWYIBlockRecord;
  338.  
  339. const unsigned long kMyGWYIBlockRecordVersion = 1;
  340.  
  341. /***********************************|****************************************/
  342.  
  343. inline AuthIdentity T2020HalfGateway::GetForwarderIdentity () const
  344. {
  345.     #if debug
  346.     if ( fForwarderIdentity == 0 )
  347.         keithDB ( "T2020HalfGateway::GetForwarderIdentity, WARNING!  Getting 0 identity." );
  348.     #endif
  349.  
  350.     return fForwarderIdentity;
  351. }
  352.  
  353. /***********************************|****************************************/
  354.  
  355. inline long T2020HalfGateway::GetServerQueueID () const
  356. {
  357.     #if debug
  358.     if ( fServerQueueID == 0 )
  359.         keithDB ( "T2020HalfGateway::GetServerQueueID, WARNING!  Getting 0 queueID." );
  360.     #endif
  361.  
  362.     return fServerQueueID;
  363. }
  364.  
  365. /***********************************|****************************************/
  366.  
  367. inline const TDirectory & T2020HalfGateway::GetAOCEDirectory () const
  368. {
  369.     return fAOCEDirectoryWeServe;
  370. }
  371.  
  372. /***********************************|****************************************/
  373.  
  374. inline AddrBlock T2020HalfGateway::GetAOCEServerHint ( ) const
  375. {
  376.     return fAOCEServerHint;
  377. }
  378.  
  379. /***********************************|****************************************/
  380.  
  381. typedef OSErr DirToolboxCallFunc ( DirParamBlock* pb );
  382. typedef OSErr AuthToolboxCallFunc ( AuthParamBlock* pb );
  383.  
  384. /***********************************|****************************************/
  385.  
  386. OSErr AOCEMakeDirToolboxCallWithRetry ( DirToolboxCallFunc dirToolboxCall, DirParamBlock* pb );
  387. OSErr AOCEMakeAuthToolboxCallWithRetry ( AuthToolboxCallFunc authToolboxCall, AuthParamBlock* pb );
  388.  
  389. /***********************************|****************************************/
  390.  
  391. #endif    // __2020HALFGATEWAY__
  392.